home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / DVDZone2.ifs < prev    next >
Encoding:
Text File  |  2004-03-20  |  7.3 KB  |  235 lines

  1. // GETINFO SCRIPTING
  2. // DVDZone2 (english)
  3.  
  4. (***************************************************
  5.  *  Movie importation script for:                  *
  6.  *      DVD Zone 2, http://www.dvdzone2.com        *
  7.  *                                                 *
  8.  *  Rewritten by Antoine Potten                    *
  9.  *  Currently it is only possible to get           *
  10.  *  information in english : cookie or session     *
  11.  *  support is needed to change language           *
  12.  *                                                 *
  13.  *  For use with Ant Movie Catalog 3.4.0           *
  14.  *  www.antp.be/software/moviecatalog              *
  15.  *                                                 *
  16.  *  This program is free software; you can         *
  17.  *  redistribute it and/or modify it under the     *
  18.  *  terms of the GNU General Public License as     *
  19.  *  published by the Free Software Foundation;     *
  20.  *  either version 2 of the License, or (at your   *
  21.  *  option) any later version.                     *
  22.  ***************************************************)
  23.  
  24. program DVDZone2_FR;
  25. var
  26.   MovieName: string;
  27.  
  28. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  29. var
  30.   i: Integer;
  31. begin
  32.   result := -1;
  33.   if StartAt < 0 then
  34.     StartAt := 0;
  35.   for i := StartAt to List.Count-1 do
  36.     if Pos(Pattern, List.GetString(i)) <> 0 then
  37.     begin
  38.       result := i;
  39.       Break;
  40.     end;
  41. end;
  42.  
  43. procedure AnalyzePage(Address: string);
  44. var
  45.   Line, MovieItem, MovieTitle, MovieAddress: string;
  46.   TitlePos, BeginPos, EndPos: Integer;
  47.   List: TStringList;
  48. begin
  49.   Line := GetPage(Address);
  50.   PickTreeClear;
  51.   if Pos('</b> : 0 item(s) found<br>', Line) = 0 then
  52.   begin
  53.     PickTreeAdd('Search results from DVDZone2', '');
  54.     BeginPos := Pos('<!-- CENTRAL TABLE -->', Line);
  55.     EndPos := Pos('<!-- /CENTRAL TABLE -->', Line);
  56.     Line := Copy(Line, BeginPos, EndPos - BeginPos);
  57.     List := TStringList.Create;
  58.     repeat
  59.       TitlePos := Pos('<a href="http://www.dvdzone2.com/dvd/detail.asp', Line);
  60.       if TitlePos > 0 then
  61.       begin
  62.         Delete(Line, 1, TitlePos);
  63.         MovieItem := Copy(Line, 1, Pos('add2basket', Line));
  64.         BeginPos := Pos('"', MovieItem) + 1;
  65.         EndPos := Pos('" class', MovieItem);
  66.         MovieAddress := Copy(MovieItem, BeginPos, EndPos - BeginPos);
  67.         BeginPos := Pos('">', MovieItem) + 2;
  68.         EndPos := Pos('</a>', MovieItem);
  69.         MovieTitle := Copy(MovieItem, BeginPos, EndPos - BeginPos);
  70.         List.Text := MovieItem;
  71.         MovieItem := Trim(List.GetString(3));
  72.         if MovieItem <> '' then
  73.           MovieTitle := MovieTitle + ' [' + MovieItem + ']';
  74.         MovieItem := Trim(List.GetString(9));
  75.         if MovieItem <> '' then
  76.           MovieTitle := MovieTitle + ' (' + MovieItem + ')';
  77.         PickTreeAdd(MovieTitle, MovieAddress);
  78.         Delete(Line, 1, 25);
  79.       end;
  80.     until TitlePos = 0;
  81.     List.Free;
  82.   end;
  83.   if PickTreeExec(Address) then
  84.     AnalyzeMoviePage(Address);
  85. end;
  86.  
  87. procedure AnalyzeMoviePage(Address: string);
  88. var
  89.   Line, Value, FullValue: string;
  90.   LineNr: Integer;
  91.   BeginPos, EndPos: Integer;
  92.   Page: TStringList;
  93. begin
  94.   Line := GetPage(Address);
  95.   BeginPos := Pos('<!-- CENTRAL TABLE -->', Line);
  96.   EndPos := Pos('<!-- /CENTRAL TABLE -->', Line);
  97.   Line := Copy(Line, BeginPos, EndPos - BeginPos);
  98.   
  99.   // title
  100.   BeginPos := Pos('<span class="detail-title">', Line);
  101.   Delete(Line, 1, BeginPos);
  102.   BeginPos := Pos('>', Line) + 1;
  103.   EndPos := Pos('</', Line);
  104.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  105.   HTMLDecode(Value);
  106.   SetField(fieldOriginalTitle, Value);
  107.   
  108.   // picture
  109.   BeginPos := Pos('http://www.dvdzone2.com/pictures/big/', Line);
  110.   if BeginPos > 0 then
  111.   begin
  112.     Delete(Line, 1, BeginPos - 1);
  113.     EndPos := Pos('"', Line);
  114.     Value := Copy(Line, 1, EndPos - 1);
  115.     GetPicture(Value, False);
  116.   end;
  117.   
  118.   // description
  119.   BeginPos := Pos('<p>', Line);
  120.   Delete(Line, 1, BeginPos + 2);
  121.   EndPos := Pos(#13, Line);
  122.   Value := StringReplace(Copy(Line, 1, EndPos - 1), '<p>', #13#10#13#10);
  123.   HTMLRemoveTags(Value);
  124.   HTMLDecode(Value);
  125.   SetField(FieldDescription, Value);
  126.  
  127.   // rating
  128.   BeginPos := Pos('Global rating', Line);
  129.   if BeginPos > 0 then
  130.   begin
  131.     Delete(Line, 1, BeginPos);
  132.     BeginPos := Pos('<b>', Line);
  133.     if BeginPos > 0 then
  134.     begin
  135.       BeginPos := BeginPos + 3;
  136.       EndPos := Pos(',', Line);
  137.       Value := Copy(Line, BeginPos, EndPos - BeginPos);
  138.       SetField(fieldRating, Value);
  139.     end;
  140.   end;
  141.   
  142.   Page := TStringList.Create;
  143.   BeginPos := Pos('<td height="120" width="50%" class="dvd-detail-border-c" valign="top" align="left">', Line);
  144.   Delete(Line, 1, BeginPos);
  145.   EndPos := Pos('</table>', Line);
  146.   Page.Text := Copy(Line, 1, EndPos);
  147.  
  148.   // director
  149.   SetField(fieldDirector, GetInfo('<b>Director', Page));
  150.  
  151.   // actors
  152.   SetField(fieldActors, StringReplace(GetInfo('<b>Actors', Page), ' - ', ', '));
  153.   
  154.   // country
  155.   SetField(fieldCountry, GetInfo('<b>Country', Page));
  156.  
  157.   // year
  158.   SetField(fieldYear, GetInfo('<b>Year', Page));
  159.  
  160.   // studio (producer)
  161.   SetField(fieldProducer, GetInfo('<b>Studio', Page));
  162.  
  163.   // category
  164.   SetField(fieldCategory, GetInfo('<b>Genres', Page));
  165.  
  166.   // length
  167.   Value := GetInfo('<b>Duration', Page);
  168.   EndPos := Pos('&', Value);
  169.   SetField(fieldLength, Copy(Value, 1, EndPos - 1));
  170.  
  171.   // special features (comments)
  172.   BeginPos := Pos('<span class="detail-title">Special features</span>', Line);
  173.   Delete(Line, 1, BeginPos);
  174.   EndPos := Pos('</table>', Line);
  175.   Delete(Line, EndPos, Length(Line));
  176.   FullValue := '';
  177.   repeat
  178.     BeginPos := Pos('</tr>', Line);
  179.     Delete(Line, 1, BeginPos);
  180.     BeginPos := Pos('<tr>', Line);
  181.     if BeginPos > 0 then
  182.     begin
  183.       BeginPos := Pos('<b>', Line);
  184.       if BeginPos > 0 then
  185.       begin
  186.         Value := Copy(Line, BeginPos + 3, Length(Line));
  187.         EndPos := Pos(#10, Value);
  188.         Value := StringReplace(Copy(Value, 1, EndPos - 1), '<br>', ' ');
  189.         HTMLRemoveTags(Value);
  190.         HTMLDecode(Value);
  191.         FullValue := FullValue + '- ' + Value + #13#10;
  192.       end;
  193.     end;
  194.   until (Pos('<tr>', Line) = 0) or (Pos('<b>', Line) = 0);
  195.   if FullValue <> '' then
  196.     SetField(fieldComments, 'DVD Special features:' + #13#10 + FullValue);
  197.  
  198.   Page.Free;
  199.   DisplayResults;
  200. end;
  201.  
  202. function GetInfo(Name: string; Page: TStringList): string;
  203. var
  204.   LineNr, BeginPos, EndPos: Integer;
  205.   Value, Line: string;
  206. begin
  207.   LineNr := FindLine(Name, Page, 0);
  208.   if LineNr > 0 then
  209.   begin
  210.     Line := Page.GetString(LineNr);
  211.     BeginPos := Pos(': ', Line) + 7;
  212.     EndPos := Pos('<br>', Line);
  213.     Value := Copy(Line, BeginPos, EndPos - BeginPos);
  214.     HTMLRemoveTags(Value);
  215.     HTMLDecode(Value);
  216.     Result := Value;
  217.   end else
  218.     Result := '';
  219. end;
  220.  
  221. begin
  222.   if CheckVersion(3,4,0) then
  223.   begin
  224.     MovieName := GetField(fieldOriginalTitle);
  225.     if MovieName = '' then
  226.       MovieName := GetField(fieldTranslatedTitle);
  227.     if Input('DVDZone2 Import', 'Enter the title of the movie:', MovieName) then
  228.     begin
  229.       AnalyzePage('http://www.dvdzone2.com/dvd/search.asp?t=1&kw=' + UrlEncode(MovieName) + '&kwt=t&pl=all');
  230.     end;
  231.   end else
  232.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
  233. end.
  234.  
  235.